﻿using System;
using System.Collections.Generic;

namespace Sliver.Network.WebSocket.Client
{
    public abstract class AbsWebSocketClient
    {
        public abstract bool IsConnected { get; }

        public abstract void Connect();

        public abstract void Close();
        
        public abstract void SendService(string path, object data = null);

        public abstract void SendInfo(string path, object data = null);

        public abstract void SendAction(string path, object data = null, Action callback = null);

        public abstract void SendMessage(string type, string path, object data, Action callback = null);

        protected HashSet<IWebSocketClientListener> Listeners = new HashSet<IWebSocketClientListener>();

        public void AddListener(IWebSocketClientListener listener)
        {
            Listeners.Add(listener);
        }

        public void RemoveListener(IWebSocketClientListener listener)
        {
            Listeners.Remove(listener);
        }
    }

    public class FakeWebSocketClient : AbsWebSocketClient
    {
        public override bool IsConnected => false;

        public override void Connect()
        {
        }

        public override void Close()
        {
        }

        public override void SendService(string path, object data = null)
        {
        }

        public override void SendInfo(string path, object data = null)
        {
        }

        public override void SendAction(string path, object data = null, Action callback = null)
        {
        }

        public override void SendMessage(string type, string path, object data, Action callback = null)
        {
        }
    }
}
